## Figure A7: Clustering of Closing Dates by Day of Week and Neighborhood Income

## install.packages(c("tidyverse"))
## library(tidyverse)

## SET WORKING DIRECTORY HERE
## setwd()

## Loading data
## load("dta.RData")

clustering_days_of_week_inc = dta %>%
  filter(!is.na(close_day_of_week)) %>%
  filter(!is.na(inc_third)) %>%
  mutate(n = 1,
         close_day_of_week = factor(close_day_of_week, levels = c("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"))) %>%
  group_by(inc_third, close_day_of_week) %>%
  summarise(n_requests_closed = sum(n, na.rm = TRUE)) %>%
  ggplot(aes(x = factor(close_day_of_week), y = n_requests_closed, fill = factor(inc_third))) +
  geom_bar(stat = "identity", position = "dodge") +
  scale_fill_brewer(name = "Per Capita Income Tercile", palette = "Blues", labels = c("Top", "Middle", "Bottom")) +
  labs(x = "Day of Week",
       y = "# of Requests Closed") +
  theme_classic()+
  theme(axis.text.x = element_text(angle = 45, hjust = 1),
        legend.position = "bottom",
        panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_rect(colour = "black"))